#ifndef ABSTRACTDIALOG_H
#define ABSTRACTDIALOG_H
#include <QDialog>
#include "Ptr.hpp"
#include "Work.h"

using namespace OOPUtils;


class AbstractDialog : public QDialog
{

  Q_OBJECT

private:

  virtual void _openEvent () {}

  virtual void _closeEvent (int r) {}

public:

  AbstractDialog (QWidget * parent) : QDialog (parent), __pWork (NULL)
  {

  }



  void openDialog (Ptr< Work > pWork) {
    setWork (pWork); 
    _openEvent (); 
    exec ();
  }



  void setWork (Ptr< Work > pWork) {
    __pWork = pWork;
    connect (this, SIGNAL (repaintViewport()), 
      __pWork->getViewportUI (), SLOT (repaint()));
  }

  Ptr< Work > & getWork () { return __pWork; }

  const Ptr< Work > & getWork () const { return __pWork; }

protected:

  Ptr< Work > __pWork;

public slots:

  void done (int r)
  {
    _closeEvent (r);
    disconnect (this, SIGNAL (repaintViewport()), 
      __pWork->getViewportUI (), SLOT (repaint()));
    __super::done(r);
  }

signals:

  void repaintViewport ();

};

#endif // ABSTRACTDIALOG_H
